#include <stdio.h>
#include <stdlib.h>

#define kMaxSize 1001
#define NIL -1

typedef int Position;
typedef struct StringNode *String;
struct StringNode {
    char data[kMaxSize]; /* 存储字符的数组 */
    int length; /* 字符串长度 */
};

String InitStr() {
    /* 初始化一个空的字符串 */
    String s;

    s = (String)malloc(sizeof(struct StringNode));
    s->length = 0;

    return s;
}

void StrInsert(String s, int pos, String t) {
    /* pos从1开始*/
    int n, m;
    Position i;

    n = s->length;
    m = t->length;
    if ((n + m) < kMaxSize) {
        for (i = n; i >= (pos - 1); i--) { /* i=n时将结束符后移 */
            s->data[i + m] =
                s->data[i]; /*将下标pos-1开始的子串后移，给t留出空位*/
        }
        for (i = 0; i < m; i++) {
            s->data[pos - 1 + i] = t->data[i]; /* 将t插入s */
        }
        s->length = n + m;
    } else {
        printf("错误：插入将导致字符串长度超限。\n");
    }
}

void StrRemove(String s, int pos, int len) {
    /* pos从1开始 */
    int n;
    Position i;

    n = s->length;
    if ((pos + len - 1) <= n) {
        for (i = pos + len - 1; i <= n; i++) { /* i=n处理结束符 */
            s->data[i - len] = s->data[i];
        }
        s->length = n - len;
    } else {
        s->data[pos - 1] =
            '\0'; /* 从数组下标pos-1开始的所有字符都删掉 */
        s->length = pos - 1;
    }
}

Position PatternMatchBF(String s, String t) {
    int n, m, i;
    Position p;

    n = s->length;
    m = t->length;
    for (p = 0; p <= (n - m); p++) {
        for (i = 0; i < m; i++) {
            if (s->data[p + i] != t->data[i]) {
                break; /* 不匹配则从下一个位置p开始 */
            }
        }
        if (i == m) { /* 匹配成功 */
            break;
        }
    }
    if (p > (n - m)) { /* 匹配不成功 */
        p = NIL;
    }
    return p;
}
/* 算法 4-12：字符串替换算法  Replace(s, sub_s, t) */
void Replace(String s, String sub_s, String t) {
    Position pos;
    int len, m;

    len = sub_s->length;
    m = t->length;
    pos = 0;
    while (pos != NIL) {
        pos = PatternMatchBF(s, sub_s); /* 从s中找到第一次出现的sub_s */
        if (pos != NIL) {
            StrRemove(s, pos + 1, len); /* 删除sub_s */
            StrInsert(s, pos + 1, t); /* 插入t */
        }
    }
}
/* 算法 4-12 结束 */

String ReadString() {
    int i;
    String s;

    s = InitStr(); /* 创建空的字符串 */
    i = 0;
    s->data[i] = getchar();
    while (s->data[i] != '\n') {
        i++;
        s->data[i] = getchar();
    }
    s->data[i] = '\0'; /* 字符串结束符占1位 */
    s->length = i;
    return s;
}

int main(void) {
    String s, sub_s, t;
    Position p;

    s = ReadString();
    sub_s = ReadString();
    t = ReadString();
    Replace(s, sub_s, t);
    printf("%s\n", s->data);

    return 0;
}